﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NetFramework.Web.Ajax;
using System.Runtime.Serialization;

namespace NetFramework.Example.Web.Ajax
{
    [DataContract]
    public class StockQuote
    {

        public static DateTime DATE_EMPTY = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        /// <summary>
        /// The stock exchange symbol. Example: MSFT, INTC, YUM, XOM, AMZN
        /// </summary>        
        [DataMember]
        public string Symbol
        {
            get { return _Symbol; }
            set { _Symbol = value; }
        }
        private string _Symbol = "";

        /// <summary>
        /// The stock's company name
        /// </summary>        
        [DataMember]
        public string Company
        {
            get { return _Company; }
            set { _Company = value; }
        }
        private string _Company = "";

        /// <summary>
        /// The price of the stock at opening of current or last session.
        /// </summary>        
        [DataMember]
        public decimal OpenPrice
        {
            get { return _OpenPrice; }
            set { _OpenPrice = value; }
        }
        private decimal _OpenPrice = 0.00M;

        /// <summary>
        /// The current or last price for the stock.
        /// </summary>        
        [DataMember]
        public decimal LastPrice
        {
            get { return _LastPrice; }
            set { _LastPrice = value; }
        }
        private decimal _LastPrice = 0.00M;

        /// <summary>
        /// The net change from opening of the current or last trading day.
        /// </summary>
        [DataMember]
        public decimal NetChange
        {
            get { return _NetChange; }
            set { _NetChange = value; }
        }
        private decimal _NetChange = 0.00M;

        /// <summary>
        /// Time of last quote relative. Time zone is in NYSE format.
        /// </summary>
        [DataMember]
        public DateTime LastQuoteTime
        {
            get { return _LastQuoteTime; }
            set { _LastQuoteTime = value; }
        }
        private DateTime _LastQuoteTime = DATE_EMPTY; // DateTime.MinValue;

        /// <summary>
        /// Formatted string optimized for display
        /// </summary>
        [DataMember]
        public string LastQuoteTimeString
        {
            get { return LastQuoteTime.ToString("MMM d, h:mmtt"); }
            set { _LastQuoteTimeString = value; }
        }
        private string _LastQuoteTimeString = "";
    }


    public class TestAjax : CallbackHandler
    {
        [CallbackMethod]
        public StockQuote Test()
        {
            StockQuote a = new StockQuote
            {
                Company = "s",
                LastPrice = 29,
                Symbol = "ss"
            };

            return a;
        }
    }
}